<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title></title>
    <c:import url="../../header.jsp"/>
</head>
<body>
<div class="content-warp">
    <div class="dgg-list-top-warp">
        <div class="screen-search">
            <ul>
                <li>
                    <label>关键字：</label>
                    <input type="text" class="dggui-input dggui-input-large" id="searchKey" name="searchKey" placeholder="名称/编号" style="width: 190px;">
                </li>
                <li>
                    <button class="dggui-btn" onclick="tableReload();">搜索</button>
                    <button class="dggui-btn dggui-btn-primary" onclick="cleanSearch()">清空条件</button>
                </li>
            </ul>
        </div>
    </div>
    <div class="list-content">
        <div class="tool-bar">
            <div class="fl">
                <a href="javascript:void(0)" class="dggui-btn" onclick="addAssessment()">新增评估结果</a>
            </div>
        </div>
        <div class="table-warp">
            <table class="dggui-table" id="assessmentResults">

            </table>
        </div>
    </div>
</div>

<c:import url="/WEB-INF/jsp/footer.jsp"/>
<script>
    var tables;
    dggui.use(['table'], function (){
        var table = dggui.table;
        var opt={
            "elem":"#assessmentResults",
            "ajax": sysInfo.basePath +"/rzsc/evaluating/assessment_list.do",
            "fnServerParams": function (aoData) {
                //搜索条件
                aoData = $.extend(aoData, {
                    //关键字
                    searchKey : $('#searchKey').val()
                });
                return aoData;
            },
            "aoColumns": [
                {
                    "title": "序号",
                    "orderable": false,
                    "render": function(data, type, full, meta) {
                        return meta.row + 1;
                    }
                },
                // {
                //     'title': '编号',
                //     "orderable": false,
                //     "data": "resultsCode",
                //     "render": function (data, type, full, meta) {
                //         return data ? data : '';
                //     }
                // },
                {
                    'title': '评估结果名称',
                    "orderable": false,
                    "data": "resultsName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '匹配试题',
                    "orderable": false,
                    "data": "paperName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '状态',
                    "orderable": false,
                    "data": "isMatching",
                    "render": function (data, type, full, meta) {
                        if(data==1){
                            data = "已匹配"
                        }
                        if(data==2){
                            data = "未匹配"
                        }
                        return data;
                    }
                },
                {
                    'title': '最新更新时间',
                    "orderable": false,
                    "data": "updateTime",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '最后更新人',
                    "orderable": false,
                    "data": "updaterName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '操作',
                    "orderable": false,
                    "render": function(data, type, row, meta) {
                        var htm = '<a href="javascript:addAssessment(\''+row.id+'\')" class="dggui-link">修改</a>' +
                            '&nbsp;&nbsp;<a href="javascript:editRatingLevel(\''+row.id+'\')" class="dggui-link">编辑客户等级</a>';
                        return htm;
                    }
                }
            ]
        };
        tables = table.render(opt);
        // 处理dataTable 异常错误信息
        $.fn.dataTable.ext.errMode = 'none';//不抛出异常
        tables.on( 'error.dt', function ( e, settings, techNote, message ) {
            if(checkEmpty(settings.jqXHR.responseJSON.error)){dggui.dialog.errors(settings.jqXHR.responseJSON.error, 2000);}
        });
    });
    /**
     * 新增评估结果
     */
    function addAssessment(optionsId){
        var title = "";
        if(isEmpty(optionsId)){
            title = '新增评估结果';
        }else{
            title = '编辑评估结果';
        }
        dggui.dialog.loading();
        $.ajax({
            url: sysInfo.basePath+"/rzsc/evaluating/add_assessment.html",
            data:{id:optionsId},
            dataType:'html',
            success:function (res){
                dggui.dialog.loading('close');
                dggui.dialog.open({
                    title: title,
                    content: res,
                    area: '500px',
                    yes: function (index) {
                        var resultsName = $("#resultsName").val();
                        var paperId = $("#paperId").val();
                        if(isEmpty(resultsName)){
                            dggui.dialog.tip('结果名称不能为空！',$('#resultsName'));
                            return;
                        }
                        if(isEmpty(paperId)){
                            dggui.dialog.tip('匹配试题不能为空！',$('#paperId'));
                            return;
                        }
                        dggui.dialog.loading();
                        var evaluatingResults = serializeObject($("#addAssessmentForm"));
                        $.ajax({
                            url: sysInfo.basePath + "/rzsc/evaluating/save_assessment.do",
                            data: evaluatingResults,
                            dataType : "JSON",
                            success: function (res) {
                                dggui.dialog.loading('close');
                                if (res.code == 0) {
                                    dggui.dialog.succeed(res.msg);
                                    layer.close(index);
                                    tableReload();
                                } else {
                                    dggui.dialog.errors(res.msg);
                                }
                            }
                        });
                    }
                })
            }
        });
    }

    //编辑客户级别
    function editRatingLevel(resultsId) {
        var url = sysInfo.basePath + "/rzsc/evaluating/rating_level_list.html?resultsId=" + resultsId;
        window.parent.updateTab("编辑客户级别", url);
    }

    //列表刷新
    function tableReload() {
        tables.ajax.reload();
    }
</script>
</body>
</html>